/**
 * @title HHIndexAction.java 
 * @description 	网站用户主页
 * @create 			2012-8-5 下午4:43:57 By xjiujiu
 * @package 		apps.site.action
 * @copyright 		Copyright (c) 2011-2012 http://xyrj.hhtc.edu.cn.com. All right reserved
 * @version         $Id$
 * XYRJ-Java-Project
 */

package apps.site.action;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import system.config.HHConfig;
import system.pojo.HHQuestionPojo;

import apps.site.model.HHProInfoModel;

import com.xyrj.exception.HHRequestException;
import com.xyrj.mvc.HHAction;
import com.xyrj.utils.HHPage;


/**
 * 
 * @ClassName: HHProinfoAction
 * @Description:前台得到产品列表
 * @author maoyun0903(maoyun19900818@163.com);
 * @date 2012-8-22 上午8:56:21
 * @version V1.0
 */
public class HHProinfoAction extends HHAction {

	/**
	 * 构造函数 
	 * 
	 * 初始化类成员
	 * 
	 * @param request
	 * @param response
	 */
	public HHProinfoAction(HttpServletRequest request,
			HttpServletResponse response)
	{
		super(request, response);
		
		this._pojo 		= new HHQuestionPojo();
	}

	/**
	 * 首页方法
	 * 
	 * @description
	 * 
	 * @title index
	 * @return void
	 */
	public void index()
	{
		int perpage 	= 10;
		HHProInfoModel proInfoModel 	= new HHProInfoModel(this._pojo);
		@SuppressWarnings("rawtypes")
        List<Map> proInfoList 		= proInfoModel.getList(this._getPageNumber(), perpage);
		Long totalRows 			= proInfoModel.getTotalRows(null);
		String pageHtml 		= HHPage.getHtmls(
			this._getTotalPage(totalRows, perpage),
			this._view.getRequestUrl(),
			0
		);
		this._view.setRequestAttr("title", this._pojo.modelZhName);
		this._view.setRequestAttr("seoKeywords", HHConfig.SEO_KEYWORDS);
		this._view.setRequestAttr("seoDesc", HHConfig.SEO_DESC);
		this._view.setRequestAttr("proInfoList", proInfoList);
		this._view.setRequestAttr("pageHtml", pageHtml);
		
		this._view.theme("proinfo_list.jsp");
	}
	
	/**
	 * 阅读详情方法
	 * 
	 * @description
	 * 
	 * @title detail
	 * @return void
	 */
	@SuppressWarnings("rawtypes")
	public void detail()
	{
		try {
			int id 		= this._getRecordId();
			HHProInfoModel proInfoModel 	= new HHProInfoModel(this._pojo);
            Map record 	= proInfoModel.getRecordById(id);
			if(null == record) {
				this._view.alertAndGoBack("此信息已经不存在，请确认！");
				return ;
			}
			//上一篇文章
			Map lastRecord	=	proInfoModel.getLastRecodeById(id);
			//下一篇文章
			Map nextRecord =	proInfoModel.getNextRecodeById(id);
			this._view.setRequestAttr("title", record.get("proInfo_name"));
			this._view.setRequestAttr("seoKeywords", record.get("seo_keywords"));
			this._view.setRequestAttr("seoDesc", record.get("seo_desc"));
			this._view.setRequestAttr("record", record);
			this._view.setRequestAttr("last_record", lastRecord);
			this._view.setRequestAttr("next_record", nextRecord);
			
			//得到其它的案例信息
			this._getOtherProInfoList(proInfoModel, id);
			
			this._view.theme("proinfo_detail.jsp");
		} catch(HHRequestException ex) {
			this._view.alertAndGoBack(ex.getMessage());
		}
	}

	/**
	 * 得到其它安全列表
	 *  
	 * @description
	 * 
	 * @title  _getOtherCaseList
	 * @param  caseModel 当前模块的数据库操作类
	 * @param  int id 当前访问的记录ID
	 * @return void
	 */
	protected void _getOtherProInfoList(HHProInfoModel proInfoModel, int id)
	{
		@SuppressWarnings("rawtypes")
        List<Map> otherProInfoList 	= proInfoModel.getLowCurrentIdList(id);
		if(null == otherProInfoList) {
			otherProInfoList 			= proInfoModel.getBigCurrentIdList(id);
		} else if(5 > otherProInfoList.size()) {
			@SuppressWarnings("rawtypes")
            List<Map> bigProInfoList 	= proInfoModel.getBigCurrentIdList(id);
			for(int i = 0; bigProInfoList != null && i < bigProInfoList.size(); i ++) {
				otherProInfoList.add(bigProInfoList.get(i));
				if(otherProInfoList.size() >= 5) {
					break;
				}
			}
		}
		
		this._view.setRequestAttr("otherProInfoList", otherProInfoList);
	}

}
